which will then polyfill you current runtime to the point where you approximately
reach compatibility with NodeJS v0.12 run with the --harmony switch. Note
that not everything can be polyfilled; in particular WeakMaps and yield cannot
be provided this way.
CND TSort
CND TSort implements a simple tool to perform the often-needed requirement of
doing a topological sorting
over an DAG (directed acyclic graph).
It is an adaption of the npm: tsort module.
Here is the basic usage: you instantiate a graph by saying e.g.
The settings object itself and its members are optional. The strict setting
(true by default) will check for the well-formedness on the graph each time a
relationship is entered; this means you get early errors at the cost of
decreased performance. We come back to the prefixes later; the default is not
to use prefixes.
Topological sorting is all about finding a total, linear ordering of actions,
values, objects or whatever from a series of statements about the relative
ordering of pairs of such objects. This is used in many fields, for example in
package management, project management, programming language grammars and so on.
So let's say you have a todo list:
'buy books'
'buy food'
'buy food'
'cook'
'do some reading'
'eat'
'fetch money'
'go home'
'go to bank'
'go to exam'
'go to market'
Now you don't have money, foods or books at home right now, but you want to eat,
do some reading, and go to the exam after that, so clearly there are certain
orderings of events that would make more sense than other orderings. It's
perhaps not immediately clear how you can organize all these jobs when you look
at the entire list, but given any two jobs, it's often easy to see which one
should preced the other one.
Once we have instantiated a graph g, we can add dual relationships piecemeal,
the convention being that we imagine arrows or links pointing from preconditions
'down' to consequences, which is why the corresponding method is named
link_down. Calling TS.link_down g, 'buy food', 'cook' means: 'Add a link to
graph g to indicate that before I can 'cook', I have to 'buy food' first',
and so on. It is customary to symbolically write 'buy food' > 'cook' to
indicate the dependency.
In case the graph has been instantiated with a strict: yes setting, CND TSort
will validate the graph for each single new relationship; as a side effect, a
list of entries is produced and returned that reflects one of the possible
linearizations of the graph which satisfies all requirements so far. For the
purpose of demonstration, we can take advantage of that list and print it out;
we can see that the ordering of jobs will sometimes take a dramatic turn when
new requirements are added. In case you've started the graph with strict: no,
you'll have to call TS.sort g yourself to perform a validation and obtain
a serialization.—Let's try that for some obvious dependencies on our list:
The output from the above will be (re-arranged for readability):
buy food > cook
fetch money > buy food > cook
fetch money > buy food > cook > do some reading > go to exam
fetch money > buy food > cook > do some reading > go to exam > eat
go to bank > fetch money > buy food > cook > do some reading > go to exam > eat
go to bank > fetch money > buy food > cook > do some reading > go to exam > eat > buy books
go to bank > fetch money > buy food > cook > buy books > do some reading > go to exam > eat
go to bank > fetch money > go to market > buy food > cook > buy books > do some reading > go to exam > eat
Observe how the requirement 'fetch money' > 'buy books' made 'buy books'
appear at the very end of the list, and how only the additonal requirement 'buy books' > 'do some reading' managed to put the horse before the cart, as it
were. It still looks as though we're not quite done here yet, as we have to
leave house after cooking and go to the exam with an empty stomach according to
the current linearization, so some dependencies are still missing:
This makes the order of events more reasonable with each step:
go to bank > fetch money > go to market > buy food > cook > buy books > do some reading > go to exam > eat > go home
go to bank > fetch money > go to market > buy food > cook > buy books > do some reading > go to exam > eat > go home
go to bank > fetch money > go to market > buy food > buy books > go home > cook > do some reading > go to exam > eat
go to bank > fetch money > go to market > buy food > buy books > go home > cook > do some reading > eat > go to exam
The takeaway up to this point is that although you may have already entered all
relevant activities, it may or or may not be the case that the relationships
define a unique ordering—TSort will always give you some ordering, but not
necessarily the only one. TSort remains silent about that. For this reason and
because the precise ordering is dependent upon order of insertion, it may happen
that a given result looks satisfying not because the constraints entered were
both sufficient and complete, but because they happened to be added to the graph
in a fitting sequence. In the same vein, adding more constraints may or may not
change the linearization.
Furthermore, each new requirement may introduce an incompatible constraint. It
is by no means unreasonable as such to require that we want to eat before going
to the bank, but should we call TS.link_down g, 'eat', 'go to bank' at this
point in time, TSort will throw an error (immediately if set to strict,
otherwise as soon as TS.sort is called), complaining that it has detected cycle involving node 'buy food'. Had we added TS.link_down g, 'eat', 'go to bank' first, the error would have resulted upon adding the constraint
TS.link_down g, 'go to bank', 'fetch money'; in this case the message would've
been detected cycle involving node 'eat'.
a grab-bag NodeJS package mainly for functionalities that used to live in coffeenode-trm, coffeenode-bitsnpieces, and coffeenode-types
The npm package cnd receives a total of 0 weekly downloads. As such, cnd popularity was classified as not popular.
We found that cnd demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.
Package last updated on 26 Apr 2020
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.